#include <bits/stdc++.h>
using namespace std;
int f[110];
char s[20];
int main() {
  int tc;
  cin >> tc;
  while (tc--) {
    int n;
    cin >> n;
    memset(f, 0, sizeof f);
    for (int i = 0; i < n; ++i) cin >> f[i];
    for (int i = 0; i < n; ++i) {
      int k;
      cin >> k >> s;
      for (int j = 0; j < k; ++j) {
        if (s[j] == 'U') {
          f[i]--;
          if (f[i] == -1) f[i] = 9;
        } else {
          f[i]++;
          if (f[i] == 10) f[i] = 0;
        }
      }
    }
    for (int i = 0; i < n; ++i) cout << f[i] << ' ';
    cout << endl;
  }
}
